home *** CD-ROM | disk | FTP | other *** search
- Path: mail2news.demon.co.uk!genesis.demon.co.uk
- From: Lawrence Kirby <fred@genesis.demon.co.uk>
- Newsgroups: comp.arch.arithmetic,comp.lang.c,comp.lang.c++
- Subject: Re: Access carry flag from C
- Date: Thu, 22 Feb 96 13:56:18 GMT
- Organization: none
- Message-ID: <824997378snz@genesis.demon.co.uk>
- References: <Dn1C9z.DGv.0.net@indra.com> <1996Feb1922.17.19.879@koobera.math.uic.edu> <31298D20.41C6@bazis.nl> <danpop.824859220@rscernix> <312AFACE.41C6@bazis.nl>
- Reply-To: fred@genesis.demon.co.uk
- X-NNTP-Posting-Host: genesis.demon.co.uk
- X-Newsreader: Demon Internet Simple News v1.27
- X-Mail2News-Path: disperse.demon.co.uk!post.demon.co.uk!genesis.demon.co.uk
-
- In article <312AFACE.41C6@bazis.nl> fkorntne@bazis.nl "Franz Korntner" writes:
-
- >Dan Pop wrote:
-
- >> If k is negative, MAXINT-k will overflow :-)
- >
- >Later I pointed out that this was only true for unsigned numbers.
-
- If we're talking about unsigned numbers, k can't be negative.
-
- >Why should I start with the difficult case first?
-
- Unsigned numbers are the easy case to test for.
-
- >> BTW, MAXINT is spelled INT_MAX in C.
- >
- >I know that and I named it so deliberatly. Because we are testing overflow
- >of arithmetic operations we must be aware of the size of the variables. In
- >my example I didn't mention the type 'int', I just stated that I assumed
- >32 bit numbers.
-
- There is no guarantee that a particular implementations supports a 32 bit
- type. Whatever type you use you have to use the relevant limits for that
- type.
-
- >According to the (X3J11 / ANSI) standard, the constant
- >INT_MAX (and in this case most limits in limits.h) denotes the minimal
- >limit. It is possible that the physical limit is much higher (or lower
- >in the case of negative values).
-
- No. The value defined for INT_MAX in limits.h is the maximum value an int
- can hold *on that particular implementation*. The standard requires that
- INT_MAX be at least 32767 on all implementations (but it can be and
- often is higher). So on any implementation:
-
- int x = INT_MAX+1;
-
- is a guaranteed overflow.
-
-
- >As I am only interested in the physical
- >limit, the value INT_MAX has no meaning.
-
- INT_MAX defined the physical limit for ints on that implementation.
-
- >Only the compiler is fully aware
- >of these limits (and not a header file!)
-
- Not true.
-
- >and what I really miss in the
- >standard and/or implementation is a inline function 'maxlimitof(int)',
- >analogical to 'sizeof(int)'.
-
- That is precisely what INT_MAX gives you.
-
- >What will the future hold for 64 bit or larger machines. For the Alpha
- >they declared int to be a 32 bit datatype because too many coders relied
- >on this. Real pity as int should denote the natural size of the machine,
- >and in the case of the Alpha it should have been 64! But this is a
- >totally different discussion.
-
- Are 32 bit operations slower than 64 bit operations on the Alpha?
-
- --
- -----------------------------------------
- Lawrence Kirby | fred@genesis.demon.co.uk
- Wilts, England | 70734.126@compuserve.com
- -----------------------------------------
-